package com.jm3.riscar3.alu;

import com.jm3.riscar3.core.CPU;
import com.jm3.riscar3.core.Microcontroller;
import com.jm3.riscar3.interfaces.IAR3Command;
import com.jm3.riscar3.memory.Memory;
import com.jm3.riscar3.memory.Register;

public class XOR implements IAR3Command {
	
	public CPU cpu;
	public Memory memory;

	public XOR(Microcontroller mcu) {
		this.cpu = mcu.getCPU();
		this.memory = mcu.getMemory();
	}

	@Override
	public void execute(String args) throws Exception {
		Register acc = cpu.getAcc();
		int accValue = acc.readRegister();
		int operand = cpu.getGRegs()[ALUUtils.getRegisterNumber(args)].readRegister();
		int result = accValue ^ operand;
		acc.writeRegister(result);
		
		//Set flags
		cpu.getSR().setZeroFlag(ALUUtils.isZero(result));
		cpu.getSR().setNegativeFlag(ALUUtils.isEightBitNegative(result));
	}

	@Override
	public String getOpCode() {
		// TODO Auto-generated method stub
		return "00010";
	}

}
